﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Planer.Model.Validators.Base;

namespace Planer.Model.Validators
{
    public class AllocationValidator : Validator<allocation>
    {
        public override void Validate(allocation Allocation)
        {
            if (Allocation == null) throw new ArgumentNullException("Allocation", NULL_ARGUMENT_MESSAGE);

            if (Allocation.amount <= 0)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.Add("Недопустимое значение отчисления");
            }

            YesNoValidator isActiveValidator = new YesNoValidator();
            isActiveValidator.Validate(Allocation.is_active);
            if (isActiveValidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(isActiveValidator.Errors);
            }

            if (Allocation.years == 0 && Allocation.months == 0 && Allocation.days == 0)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.Add("Период не может быть пустым");
            }
        }
    }
}
